<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath();
%>
<jsp:include page="/WEB-INF/page/auth/_header.jsp"></jsp:include>
<body>
	<jsp:include page="/WEB-INF/page/auth/header.jsp"></jsp:include>
	<div id="middle">
		<jsp:include page="/WEB-INF/page/auth/menu.jsp"></jsp:include>
		<div id="right">
		    <div id="schoolAwardtb">
		        <form id="schoolAwardForm" class="m10">
	           		学期：
						<select class="form-control1" name="termId" id="termId" onchange="searchGrade(this)">
						</select>
						年级：
						<select class="form-control1" name="grade" id="grade" onchange="searchClazz(this.value)">
						</select>
						班级：
						<select id="clazz" name="clazz" class="form-control1">
						</select>
						学生姓名：
						<input id="key" name="key" class="easyui-validatebox validatebox-text" style="width:120px;">
						<input type="hidden" id="schoolId" name="schoolId" value=""/>
		            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-search'" onclick="searchForm('schoolAward')">查询</a>
		            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-clear'" onclick="resetForm('schoolAward')">重置</a><br/>
		        </form>
		    </div>
		    <table id="schoolAwarddg">
		        <thead>
		            <tr>
		                <th data-options="field:'termId',title:'学期',formatter:function(value,row,index){
		                    return row.termName;
		                }"></th>
		                <th data-options="field:'studentNum',title:'学号'"></th>
		                <th data-options="field:'studentName',title:'学生姓名'"></th>
		                <th data-options="field:'prizeName',title:'奖项'"></th>
		                <th data-options="field:'createTime',title:'创建时间',formatter:function(value,row,index){
		                    return getTime(value,'yyyy-MM-dd hh:mm:ss');
		                }"></th>
		            </tr>
		        </thead>
		    </table>
		</div>
	</div>
	<jsp:include page="/WEB-INF/page/auth/_footer.jsp"/>
	<script type="text/javascript">
		var schoolId = $("#userSchoolId").val();
        $(function(){
            var url = basePath + "/sys/student/schoolAward";
			initSchoolIdInputValue();
            initDatagrid("schoolAward", url);
            initTermList();
        });

		function initSchoolIdInputValue() {
			var v1 = $("#userSchoolId").val();
			$("#schoolId").val(v1);
		}

        function initTermList(){
		    $.ajax({
		        url: basePath + "/termList",
		        type: 'POST',
		        dataType: 'json',
				data: {schoolId: schoolId},
		        error : function(data) {
		            $.messager.progress('close');
		            $.messager.alert('系统提示', data.msg, 'error');
		        },
		        success: function (data) {
		        	var html = "";
		        	for(var i in data) {
		        		html += "<option value='"+data[i].id+"'>"+data[i].termName+"</option>";
		        	}
		            $("#termId").html(html);
		            initGradeList(data[0].termName);
		        }
		    });
		}
        function initGradeList(termName) {
			var termYear = termName.substring(0, termName.indexOf("-"))
			$.ajax({
		 		url : basePath + "/gradeByTermYear",
		 		type : "post",
		 		dataType : "json",
		 		data: {
		 			termYear: termYear
		 		},
		 		async : false,
		 		success : function(data) {
		 			var html = '';
		 			for(var i in data){
		 		        if (data.hasOwnProperty(i)) {
		 		        	html += "<option value='"+i+"'>"+ data[i] +"</option>";
		 		        };
		 		    }
		 			$("#grade").html(html);
		 			$("#grade").trigger("onchange");
		 		}, error:function(){
		 			alert("查询年级异常");
		  		}
		    });
		}
		function searchGrade() {
			initGradeList($("#termId option:selected")[0].text);
		}
		function searchClazz(grade) {
			if(!grade) return;
			$.ajax({
		 		url : basePath + "/getFullClazz?grade=" + grade,
		 		type : "GET",
		 		dataType : "json",
		 		async : false,
		 		success : function(data) {
		 			var html = '';
		 			for(var i in data){
		 		        if (data.hasOwnProperty(i)) {
		 		        	html += "<option value='"+data[i]+"'>"+ data[i] +"班</option>";
		 		        };
		 		    }
		 			$("#clazz").html(html);
		 			if(!dataGrid){
		 				loadData();
		 			}
		 		}, error:function(){
		 			alert("查询班级异常");
		  		}
		    });
		}
    </script>
</body>
</html>